﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class ResetItemList
{
    #region Singleton

    private static ResetItemList instance = null;

    private ResetItemList()
    {
    }

    public static ResetItemList Instance
    {
        get
        {
            if (instance == null) instance = new ResetItemList();
            return instance;
        }
    }

    #endregion

    #region Member Variables

    private List<IResettable> resettables = new List<IResettable>();

    #endregion

    #region Public Methods

    public void AddItem(IResettable resettable)
    {
        if (!resettables.Contains(resettable)) resettables.Add(resettable);
    }

    public void RemoveItem(IResettable resettable)
    {
        if (resettables.Contains(resettable)) resettables.Remove(resettable);
    }

    public List<IResettable> GetItems()
    {
        return resettables;
    }

    public void ResetItems()
    {
        List<IResettable> newList = new List<IResettable>();

        foreach (IResettable resettable in resettables)
        {
            if (resettable != null)
            {
                resettable.Reset();
                if (resettable.PersistAfterReset())
                {
                    newList.Add(resettable);
                }
            }
        }

        resettables = newList;
    }

    #endregion

    internal void Clear()
    {
        resettables.Clear();
    }
}
